package com.aps.apspda.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.aps.apspda.R;
import com.aps.apspda.activity.CurrentEqpPercentActivity;
import com.aps.apspda.activity.MyWorkActivity;
import com.aps.apspda.activity.SearchInfoActivity;
import com.aps.apspda.adapter.TabIndexGridAdapter;
import com.aps.apspda.entity.TabIndexGridEntity;
import com.aps.apspda.utils.StaticMembers;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;


public class InfoFragment extends Fragment {

    @BindView(R.id.rvGrid)
    RecyclerView rvGrid;


    private Unbinder unbinder;

    public InfoFragment() {
        // Required empty public constructor
    }

    public static InfoFragment createNewInstance() {
        return new InfoFragment();
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_info, container, false);
        unbinder = ButterKnife.bind(this, view);
        initView();
        initData();
        return view;
    }

    private void initView() {
        rvGrid.setLayoutManager(new GridLayoutManager(getActivity(), 3));
    }

    private void initData() {
        List<TabIndexGridEntity> list = new ArrayList<>();
        if (StaticMembers.CUR_USER.getFEATURESCODE().contains("I0")) {
            list.add(new TabIndexGridEntity(R.drawable.info_search, "批次当前信息查询", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivity(new Intent(getActivity(), SearchInfoActivity.class));
                }
            }));
        }
        if (StaticMembers.CUR_USER.getFEATURESCODE().contains("I1")) {
            list.add(new TabIndexGridEntity(R.drawable.shebei_search, "当前设备作业量", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivity(new Intent(getActivity(), CurrentEqpPercentActivity.class));
                }
            }));
        }
        if (StaticMembers.CUR_USER.getFEATURESCODE().contains("I2")) {
            list.add(new TabIndexGridEntity(R.drawable.mine_shebei, "本人设备作业信息", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivity(new Intent(getActivity(), MyWorkActivity.class));
                }
            }));
        }
        TabIndexGridAdapter tabIndexGridAdapter = new TabIndexGridAdapter(list);
        tabIndexGridAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        tabIndexGridAdapter.isFirstOnly(true);
        rvGrid.setAdapter(tabIndexGridAdapter);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
